"use strict";
var domArr = [{
        name: "首页",
        url: "./第一页.html"
    },
    {
        name: "第二页",
        url: "./第二页.html"
    },
    {
        name: "第三页",
        url: "./第三页.html"
    },
    {
        name: "第四页",
        url: "./第四页.html"
    },
    {
        name: "第六页",
        url: "./第六页.html"
    }];
function $(dom) {
    return document.querySelector(dom);
}
var Stefocuse = /** @class */ (function () {
    function Stefocuse(box, name) {
        this.Boxheight = Number(window.innerHeight / 2);
        this.box = $(box);
        this.name = name;
        this.pageY = 0;
        this.pageX = 0;
        this.move = false;
        this.Down();
        this.scroll();
    }
    Stefocuse.prototype.Down = function () {
        var _this_1 = this;
        var _this = this;
        var downY = 0;
        var UPY = 0;
        this.myAddEvent(this.box, 'mousedown', function (event) {
            downY = 0;
            UPY = 0;
            downY = event.y;
            _this_1.box.onmousemove = function (event) {
                // ({ x: _this.pageX, y: _this.pageY } = event);
                _this.move = true;
            };
        });
        this.myAddEvent(this.box, 'mouseup', function (event) {
            if (_this.move) {
                UPY = event.y;
                if (UPY - downY > 200 || UPY - downY < 200) {
                    var bool = downY < UPY ? true : false;
                    _this_1.tebHref(bool, _this_1.name);
                    _this_1.box.onmousemove = null;
                }
            }
        });
    };
    Stefocuse.prototype.myAddEvent = function (ele, type, fun) {
        if (ele.addEventListener) {
            ele.addEventListener(type, fun);
        }
        else {
            ele.attachEvent('on' + type, fun);
        }
    };
    Stefocuse.prototype.tebHref = function (bool, text) {
        var index = this.getArrayIndex(bool, text);
        if (text != domArr[index].name) {
            this.box.onmousemove = null;
            this.pageX = 0;
            this.pageY = 0;
            this.move = false;
            window.location.href = domArr[index].url;
        }
    };
    Stefocuse.prototype.getArrayIndex = function (bool, text) {
        debugger;
        var i = domArr.length;
        var index = 0;
        while (i--) {
            if (domArr[i].name === text) {
                index = i;
            }
        }
        if (bool) {
            index = index >= domArr.length - 1 ? domArr.length - 1 : index + 1;
        }
        else {
            index = index <= 0 ? 0 : index - 1;
        }
        return index;
    };
    /* 鼠标滚动事件 */
    Stefocuse.prototype.scroll = function () {
        window.onmousewheel = null;
        var _this = this;
        var bool = false;
        var scrollFunc = function (e) {
            e = e || window.event;
            if (e.wheelDelta) { //判断浏览器IE，谷歌滑轮事件               
                if (e.wheelDelta > 0) { //当滑轮向上滚动时  
                    bool = false;
                }
                if (e.wheelDelta < 0) { //当滑轮向下滚动时  
                    bool = true;
                }
            }
            _this.tebHref(bool, _this.name);
        };
        //给页面绑定滑轮滚动事件  
        if (document.addEventListener) { //firefox  
            document.addEventListener('DOMMouseScroll', scrollFunc, false);
        }
        //滚动滑轮触发scrollFunc方法  //ie 谷歌  
        setTimeout(function () {
            window.onmousewheel = scrollFunc;
        }, 300);
    };
    return Stefocuse;
}());
